// page/pack-service/pages/work-guide/work-guide.js
var toolUtils = require("../../../../utils/tool-utils.js")
var httpUtils = require('../../../../utils/https-service-utils.js')
var that
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkId: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this
    getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onClickItem: function (e) {
    var index = e.currentTarget.dataset.index
    that.setData({
      checkId: index
    })
  },
  /**
   * 办事指南的分类
   */
  onClassify: function () {
    toolUtils.pageTo("/page/pack-service/pages/work-guide/classify/classify?tag=" + that.data.checkId)
  },
  /**
 * 搜索
 */
  formSearch: function (e) {
    var q = e.detail.value.q
    if (!!that.data.classify && that.data.checkId == that.data.classify.tag){
      toolUtils.pageTo("/page/pack-service/pages/work-guide/list/list?top_id=" + that.data.classifyData[that.data.checkId].attr_id + "&attr_id=" + that.data.classify.attr_id+"&q="+q)
    }else{
      toolUtils.pageTo("/page/pack-service/pages/work-guide/list/list?top_id=" + that.data.classifyData[that.data.checkId].attr_id + "&attr_id=" + ''+ "&q=" + q)
      // toolUtils.showFailToast("请选择分类")
    }
    
  }
})
function getData() {
  httpUtils.getBaznAttr({}, function (res) {
    that.setData({
      classifyData:res
    })
  }, function (e) {

  })
}